[WIP] Add local value numbering implementation in ZJIT#4
Draft
[WIP] Add local value numbering implementation in ZJIT#4
Conversation
Don't abort the entire compilation. Fix Shopify#700
Copilot stopped work on behalf of
tekknolagi due to an error
February 1, 2026 19:48
Copilot stopped work on behalf of
tekknolagi due to an error
February 1, 2026 20:00
tekknolagi
pushed a commit
that referenced
this pull request
Mar 24, 2026
When we call `asm.load`, many times we're passing in a VReg, and that
causes extra loads when we lower to machine code. I'd like to only emit
a load in the case that the operand _isn't_ a VReg.
For example this code:
```ruby
class Foo
def initialize
@foo = 123
end
def foo
@foo
end
end
foo = Foo.new
5.times { foo.foo }
```
Before this patch, the machine code for `LoadField` looks like this:
```
# Insn: v18 LoadField v17, :_shape_id@0x4
# Load field id=_shape_id offset=4
0x121308320: mov x1, x0
0x121308324: ldur w1, [x1, #4]
```
Now it looks like this:
```
# Insn: v18 LoadField v17, :_shape_id@0x4
# Load field id=_shape_id offset=4
0x12339c320: ldur w1, [x0, #4]
```
We were able to eliminate a reg-reg copy.
tekknolagi
pushed a commit
that referenced
this pull request
Apr 6, 2026
pm_parse_process initializes the index_lookup_table but nothing seems to
use it after it has been allocated. However, pm_compile_scope_node will
overwrite the index_lookup_table and cause it to leak memory. This can
be seen during bootup with the following memory leaks reported by ASAN:
#0 0x60dba31b7af3 in malloc
#1 0x60dba32e0718 in rb_gc_impl_malloc gc/default/default.c:8287:5
#2 0x60dba32c7aa7 in ruby_xmalloc_body gc.c:5373:12
#3 0x60dba32c4a54 in ruby_xmalloc gc.c:5355:34
#4 0x60dba3260314 in pm_index_lookup_table_init_heap prism_compile.h:89:29
#5 0x60dba3209388 in pm_parse_process prism_compile.c:11366:5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implementation Plan for Local Value Numbering in ZJIT
Overview
Implement local value numbering (LVN) optimization to eliminate redundant computations within basic blocks. The Effect/AbstractHeap API already exists in the upstream codebase (
zjit/src/hir_effect), so we'll use and potentially extend it as needed.Implementation Checklist
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.